﻿namespace Yipusoft.BaseDoc
{
    using System;
    using System.ComponentModel;
    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    using System.Runtime.CompilerServices;

    [Table(Name="dbo.BaseDocFiles")]
    public class BaseDocFiles : INotifyPropertyChanging, INotifyPropertyChanged
    {
        private EntityRef<Yipusoft.BaseDoc.BaseDocs> _BaseDocs = new EntityRef<Yipusoft.BaseDoc.BaseDocs>();
        private Guid? _DID;
        private string _FileName;
        private string _FileTitle;
        private string _FileType;
        private Guid _ID;
        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(string.Empty);

        public event PropertyChangedEventHandler PropertyChanged;

        public event PropertyChangingEventHandler PropertyChanging;

        protected virtual void SendPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected virtual void SendPropertyChanging()
        {
            if (this.PropertyChanging != null)
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        [Association(Name="BaseDocs_BaseDocFiles", Storage="_BaseDocs", ThisKey="DID", OtherKey="ID", IsForeignKey=true)]
        public Yipusoft.BaseDoc.BaseDocs BaseDocs
        {
            get
            {
                return this._BaseDocs.Entity;
            }
            set
            {
                Yipusoft.BaseDoc.BaseDocs entity = this._BaseDocs.Entity;
                if ((entity != value) || !this._BaseDocs.HasLoadedOrAssignedValue)
                {
                    this.SendPropertyChanging();
                    if (entity != null)
                    {
                        this._BaseDocs.Entity = null;
                        entity.BaseDocFiles.Remove(this);
                    }
                    this._BaseDocs.Entity = value;
                    if (value != null)
                    {
                        value.BaseDocFiles.Add(this);
                        this._DID = new Guid?(value.ID);
                    }
                    else
                    {
                        this._DID = null;
                    }
                    this.SendPropertyChanged("BaseDocs");
                }
            }
        }

        [Column(Storage="_DID", DbType="UniqueIdentifier")]
        public Guid? DID
        {
            get
            {
                return this._DID;
            }
            set
            {
                if (this._DID != value)
                {
                    if (this._BaseDocs.HasLoadedOrAssignedValue)
                    {
                        throw new ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging();
                    this._DID = value;
                    this.SendPropertyChanged("DID");
                }
            }
        }

        [Column(Storage="_FileName", DbType="NVarChar(500)")]
        public string FileName
        {
            get
            {
                return this._FileName;
            }
            set
            {
                if (this._FileName != value)
                {
                    this.SendPropertyChanging();
                    this._FileName = value;
                    this.SendPropertyChanged("FileName");
                }
            }
        }

        [Column(Storage="_FileTitle", DbType="NVarChar(200)")]
        public string FileTitle
        {
            get
            {
                return this._FileTitle;
            }
            set
            {
                if (this._FileTitle != value)
                {
                    this.SendPropertyChanging();
                    this._FileTitle = value;
                    this.SendPropertyChanged("FileTitle");
                }
            }
        }

        [Column(Storage="_FileType", DbType="VarChar(10)")]
        public string FileType
        {
            get
            {
                return this._FileType;
            }
            set
            {
                if (this._FileType != value)
                {
                    this.SendPropertyChanging();
                    this._FileType = value;
                    this.SendPropertyChanged("FileType");
                }
            }
        }

        [Column(Storage="_ID", DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true)]
        public Guid ID
        {
            get
            {
                return this._ID;
            }
            set
            {
                if (this._ID != value)
                {
                    this.SendPropertyChanging();
                    this._ID = value;
                    this.SendPropertyChanged("ID");
                }
            }
        }
    }
}

